﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Package_ViewPackage : AdminBasePage
{

    public vPackageDetail Package { get; set; }
    string barcode;
    protected void Page_Load(object sender, EventArgs e)
    {
        BLLConfirmShipment bll = new BLLConfirmShipment();
        barcode = Request.QueryString["barcode"];

        if (!string.IsNullOrEmpty(barcode))
        {
            barcode = barcode.Replace("+", "");
            tblPackage package = bll.getPackageByBarcode(barcode);
            if (package != null)
            {
                ViewState["packageid"] = package.ID;
                Package = bll.getPackageInformation(package.ID);
                bindTransit();
                panelInfo.Visible = true;
            }
            else
            {
                panelInfo.Visible = false;
                Response.Redirect("~/Admin/Index.aspx");
            }
            Page.DataBind();
            
        }
        else
        {
            Response.Redirect("~/Admin/Index.aspx");
            //Response.Redirect("~/Admin/Package/ListPackage.aspx");
        }

        
    }

    private void bindTransit()
    {
        DALTransit dalTransit = new DALTransit();
        List<vTransitRecord> lstTransit = dalTransit.GetPackagevTransits(Package.ID);
        if (lstTransit.Count > 0)
        {
            dlTransit.DataSource = lstTransit;
            dlTransit.DataBind();
        }
        else
        {
            divRoute.Visible = false;
        }


    }
    protected void btnEdit_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/Package/EditPackage.aspx?barcode=" + barcode);
    }
}